<?php
/*
	Copyright (C) 2008 - 2012 Inanta Martsanto
	Inanta Martsanto (inanta@inationsoft.com)

	This file is part of Koma.

	Koma is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	Koma is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Koma.  If not, see <http://www.gnu.org/licenses/>.
*/

namespace Inationsoft\Koma;

use Inationsoft\NS;

define('KOMA_SORT_ASCENDING', 0);
define('KOMA_SORT_DESCENDING', 1);

define('KOMA_FILTER_SIMPLE', 1);
define('KOMA_FILTER_REGEX', 0);

/**
 *Get multiple list
 *
 *@author Inanta Martsanto <inanta@inationsoft.com>
 */
final class Lists {
	public static function getFileList($path, $filters = '*', $filter_type = KOMA_FILTER_SIMPLE, $sort = KOMA_SORT_ASCENDING)
	{
		$filters = (is_array($filters)) ? $filters : (explode('|', $filters));
		$files = @scandir($path);
		$ret_files = array();
				
		foreach($files as $file)
		{
			if(!is_dir($path.'/'.$file) && $file{0} != '.')
			{
				foreach($filters as $filter)
				{
					if($filter == '*' ||
					   ($filter_type == KOMA_FILTER_SIMPLE && in_array(substr($file, strrpos($file, '.') + 1, strlen($file) - strrpos($file, '.') + 1), $filters)) ||
					   ($filter_type == KOMA_FILTER_REGEX && @preg_match('/'.$filter.'/', $file)))
					{
						if(!in_array($file, $ret_files))
						{
							$ret_files[] = $file;
						}   
					}
				}
			}
		}
		
		if ($sort == KOMA_SORT_DESCENDING)
		{
			rsort($ret_files);
		}
		
		return $ret_files;
	}

	public static function getDirectoryList($path, $filters = '*', $filter_type = KOMA_FILTER_SIMPLE, $sort = KOMA_SORT_ASCENDING)
	{
		$files = @scandir($path);
		$filters = (is_array($filters)) ? $filters : (explode('|', $filters));
		$dir = array();
		
		foreach($files as $file)
		{
			if(is_dir($path.'/'.$file) && $file{0} != '.')
			{
				foreach($filters as $filter)
				{
					if($filter_type == KOMA_FILTER_SIMPLE)
					{
						$pos = strpos($file, str_replace('%', '', $filter));
						$rpos = strrpos($file, str_replace('%', '', $filter));					   
					}

					if($filter == '*' ||
					   ($filter_type == KOMA_FILTER_SIMPLE &&
							(substr($filter, 0, 1) == '%' && substr($file, -(strlen(str_replace('%', '', $filter))), strlen(str_replace('%', '', $filter))) == str_replace('%', '', $filter) && substr($filter, -1, 1) != '%') ||
							(substr($filter, -1, 1) == '%' && $pos === 0 && substr($filter, 0, 1) != '%') ||
							(substr($filter, 0, 1) == '%' && substr($filter, -1, 1) == '%' && $pos == $rpos && $pos != false && substr($file, -(strlen(str_replace('%', '', $filter))), strlen(str_replace('%', '', $filter))) != str_replace('%', '', $filter))) ||
					   ($filter_type == KOMA_FILTER_REGEX && @preg_match('/'.$filter.'/', $file)))
					{
						if(!in_array($file, $dir))
						{
							$dir[] = $file;
						}   
					}
				}
			}
		}
		
		if ($sort == KOMA_SORT_DESCENDING)
		{
			rsort($dir);
		}
		
		return $dir;
	}

	public static function getMonths()
	{
		$month = array(
				'1' => T_('January'),
				'2' => T_('February'),
				'3' => T_('March'),
				'4' => T_('April'),
				'5' => T_('May'),
				'6' => T_('June'),
				'7' => T_('July'),
				'8' => T_('August'),
				'9' => T_('September'),
				'10' => T_('October'),
				'11' => T_('November'),
				'12' => T_('December'));
		
		return $month;
	}

	public static function getCountries($sort = KOMA_SORT_ASCENDING)
	{
		gettext_init(KOMA_LOCALE, 'country', KOMA_LOCALE_PATH, KOMA_CHARSET);
		
		$country_list = array (
				'AD' => T_('Andorra'),
				'AE' => T_('United Arab Emirates'),
				'AF' => T_('Afghanistan'),
				'AG' => T_('Antigua and Barbuda'),
				'AI' => T_('Anguilla'),
				'AL' => T_('Albania'),
				'AM' => T_('Armenia'),
				'AN' => T_('Netherlands Antilles'),
				'AO' => T_('Angola'),
				'AQ' => T_('Antarctica'),
				'AR' => T_('Argentina'),
				'AS' => T_('American Samoa'),
				'AT' => T_('Austria'),
				'AU' => T_('Australia'),
				'AW' => T_('Aruba'),
				'AZ' => T_('Azerbaijan'),
				'BA' => T_('Bosnia and Herzegovina'),
				'BB' => T_('Barbados'),
				'BD' => T_('Bangladesh'),
				'BE' => T_('Belgium'),
				'BF' => T_('Burkina Faso'),
				'BG' => T_('Bulgaria'),
				'BH' => T_('Bahrain'),
				'BI' => T_('Burundi'),
				'BJ' => T_('Benin'),
				'BM' => T_('Bermuda'),
				'BN' => T_('Brunei Darussalam'),
				'BO' => T_('Bolivia'),
				'BR' => T_('Brazil'),
				'BS' => T_('Bahamas'),
				'BT' => T_('Bhutan'),
				'BV' => T_('Bouvet Island'),
				'BW' => T_('Botswana'),
				'BY' => T_('Belarus'),
				'BZ' => T_('Belize'),
				'CA' => T_('Canada'),
				'CC' => T_('Cocos (Keeling) Islands'),
				'CF' => T_('Central African Republic'),
				'CG' => T_('Congo'),
				'CH' => T_('Switzerland'),
				'CI' => T_("Cote D'Ivoire (Ivory Coast)"),
				'CK' => T_('Cook Islands'),
				'CL' => T_('Chile'),
				'CM' => T_('Cameroon'),
				'CN' => T_('China'),
				'CO' => T_('Colombia'),
				'CR' => T_('Costa Rica'),
				'CS' => T_('Czechoslovakia (former)'),
				'CU' => T_('Cuba'),
				'CV' => T_('Cape Verde'),
				'CX' => T_('Christmas Island'),
				'CY' => T_('Cyprus'),
				'CZ' => T_('Czech Republic'),
				'DE' => T_('Germany'),
				'DJ' => T_('Djibouti'),
				'DK' => T_('Denmark'),
				'DM' => T_('Dominica'),
				'DO' => T_('Dominican Republic'),
				'DZ' => T_('Algeria'),
				'EC' => T_('Ecuador'),
				'EE' => T_('Estonia'),
				'EG' => T_('Egypt'),
				'EH' => T_('Western Sahara'),
				'ER' => T_('Eritrea'),
				'ES' => T_('Spain'),
				'ET' => T_('Ethiopia'),
				'FI' => T_('Finland'),
				'FJ' => T_('Fiji'),
				'FK' => T_('Falkland Islands (Malvinas)'),
				'FM' => T_('Micronesia'),
				'FO' => T_('Faroe Islands'),
				'FR' => T_('France'),
				'FX' => T_('France, Metropolitan'),
				'GA' => T_('Gabon'),
				'GB' => T_('Great Britain (UK)'),
				'GD' => T_('Grenada'),
				'GE' => T_('Georgia'),
				'GF' => T_('French Guiana'),
				'GH' => T_('Ghana'),
				'GI' => T_('Gibraltar'),
				'GL' => T_('Greenland'),
				'GM' => T_('Gambia'),
				'GN' => T_('Guinea'),
				'GP' => T_('Guadeloupe'),
				'GQ' => T_('Equatorial Guinea'),
				'GR' => T_('Greece'),
				'GS' => T_('S. Georgia and S. Sandwich Isls.'),
				'GT' => T_('Guatemala'),
				'GU' => T_('Guam'),
				'GW' => T_('Guinea-Bissau'),
				'GY' => T_('Guyana'),
				'HK' => T_('Hong Kong'),
				'HM' => T_('Heard and McDonald Islands'),
				'HN' => T_('Honduras'),
				'HR' => T_('Croatia (Hrvatska)'),
				'HT' => T_('Haiti'),
				'HU' => T_('Hungary'),
				'ID' => T_('Indonesia'),
				'IE' => T_('Ireland'),
				'IL' => T_('Israel'),
				'IN' => T_('India'),
				'IO' => T_('British Indian Ocean Territory'),
				'IQ' => T_('Iraq'),
				'IR' => T_('Iran'),
				'IS' => T_('Iceland'),
				'IT' => T_('Italy'),
				'JM' => T_('Jamaica'),
				'JO' => T_('Jordan'),
				'JP' => T_('Japan'),
				'KE' => T_('Kenya'),
				'KG' => T_('Kyrgyzstan'),
				'KH' => T_('Cambodia'),
				'KI' => T_('Kiribati'),
				'KM' => T_('Comoros'),
				'KN' => T_('Saint Kitts and Nevis'),
				'KP' => T_('Korea (North)'),
				'KR' => T_('Korea (South)'),
				'KW' => T_('Kuwait'),
				'KY' => T_('Cayman Islands'),
				'KZ' => T_('Kazakhstan'),
				'LA' => T_('Laos'),
				'LB' => T_('Lebanon'),
				'LC' => T_('Saint Lucia'),
				'LI' => T_('Liechtenstein'),
				'LK' => T_('Sri Lanka'),
				'LR' => T_('Liberia'),
				'LS' => T_('Lesotho'),
				'LT' => T_('Lithuania'),
				'LU' => T_('Luxembourg'),
				'LV' => T_('Latvia'),
				'LY' => T_('Libya'),
				'MA' => T_('Morocco'),
				'MC' => T_('Monaco'),
				'MD' => T_('Moldova'),
				'MG' => T_('Madagascar'),
				'MH' => T_('Marshall Islands'),
				'MK' => T_('Macedonia'),
				'ML' => T_('Mali'),
				'MM' => T_('Myanmar'),
				'MN' => T_('Mongolia'),
				'MO' => T_('Macau'),
				'MP' => T_('Northern Mariana Islands'),
				'MQ' => T_('Martinique'),
				'MR' => T_('Mauritania'),
				'MS' => T_('Montserrat'),
				'MT' => T_('Malta'),
				'MU' => T_('Mauritius'),
				'MV' => T_('Maldives'),
				'MW' => T_('Malawi'),
				'MX' => T_('Mexico'),
				'MY' => T_('Malaysia'),
				'MZ' => T_('Mozambique'),
				'NA' => T_('Namibia'),
				'NC' => T_('New Caledonia'),
				'NE' => T_('Niger'),
				'NF' => T_('Norfolk Island'),
				'NG' => T_('Nigeria'),
				'NI' => T_('Nicaragua'),
				'NL' => T_('Netherlands'),
				'NO' => T_('Norway'),
				'NP' => T_('Nepal'),
				'NR' => T_('Nauru'),
				'NT' => T_('Neutral Zone'),
				'NU' => T_('Niue'),
				'NZ' => T_('New Zealand (Aotearoa)'),
				'OM' => T_('Oman'),
				'PA' => T_('Panama'),
				'PE' => T_('Peru'),
				'PF' => T_('French Polynesia'),
				'PG' => T_('Papua New Guinea'),
				'PH' => T_('Philippines'),
				'PK' => T_('Pakistan'),
				'PL' => T_('Poland'),
				'PM' => T_('St. Pierre and Miquelon'),
				'PN' => T_('Pitcairn'),
				'PR' => T_('Puerto Rico'),
				'PT' => T_('Portugal'),
				'PW' => T_('Palau'),
				'PY' => T_('Paraguay'),
				'QA' => T_('Qatar'),
				'RE' => T_('Reunion'),
				'RO' => T_('Romania'),
				'RU' => T_('Russian Federation'),
				'RW' => T_('Rwanda'),
				'SA' => T_('Saudi Arabia'),
				'Sb' => T_('Solomon Islands'),
				'SC' => T_('Seychelles'),
				'SD' => T_('Sudan'),
				'SE' => T_('Sweden'),
				'SG' => T_('Singapore'),
				'SH' => T_('St. Helena'),
				'SI' => T_('Slovenia'),
				'SJ' => T_('Svalbard and Jan Mayen Islands'),
				'SK' => T_('Slovak Republic'),
				'SL' => T_('Sierra Leone'),
				'SM' => T_('San Marino'),
				'SN' => T_('Senegal'),
				'SO' => T_('Somalia'),
				'SR' => T_('Suriname'),
				'ST' => T_('Sao Tome and Principe'),
				'SU' => T_('USSR (former)'),
				'SV' => T_('El Salvador'),
				'SY' => T_('Syria'),
				'SZ' => T_('Swaziland'),
				'TC' => T_('Turks and Caicos Islands'),
				'TD' => T_('Chad'),
				'TF' => T_('French Southern Territories'),
				'TG' => T_('Togo'),
				'TH' => T_('Thailand'),
				'TJ' => T_('Tajikistan'),
				'TK' => T_('Tokelau'),
				'TM' => T_('Turkmenistan'),
				'TN' => T_('Tunisia'),
				'TO' => T_('Tonga'),
				'TP' => T_('East Timor'),
				'TR' => T_('Turkey'),
				'TT' => T_('Trinidad and Tobago'),
				'TV' => T_('Tuvalu'),
				'TW' => T_('Taiwan'),
				'TZ' => T_('Tanzania'),
				'UA' => T_('Ukraine'),
				'UG' => T_('Uganda'),
				'UK' => T_('United Kingdom'),
				'UM' => T_('US Minor Outlying Islands'),
				'US' => T_('United States'),
				'UY' => T_('Uruguay'),
				'UZ' => T_('Uzbekistan'),
				'VA' => T_('Vatican City State (Holy See)'),
				'VC' => T_('Saint Vincent and the Grenadines'),
				'VE' => T_('Venezuela'),
				'VG' => T_('Virgin Islands (British)'),
				'VI' => T_('Virgin Islands (U.S.)'),
				'VN' => T_('Viet Nam'),
				'VU' => T_('Vanuatu'),
				'WF' => T_('Wallis and Futuna Islands'),
				'WS' => T_('Samoa'),
				'YE' => T_('Yemen'),
				'YT' => T_('Mayotte'),
				'YU' => T_('Yugoslavia'),
				'ZA' => T_('South Africa'),
				'ZM' => T_('Zambia'),
				'ZR' => T_('Zaire'),
				'ZW' => T_('Zimbabwe'));
		
		$sort == KOMA_SORT_ASCENDING ? asort($country_list) : arsort($country_list);
		
		return $country_list;
	}

	public static function getTimezones()
	{
		gettext_init(KOMA_LOCALE, 'timezone', KOMA_LOCALE_PATH, KOMA_CHARSET);

		return array(
				'-12' => T_('(GMT-12:00) Eniwetok, Kwajalein'),
				'-11' => T_('(GMT-11:00) Midway Island, Samoa'),
				'-10' => T_('(GMT-10:00) Hawaii'),
				'-9' => T_('(GMT-9:00) Alaska'),
				'-8' => T_('(GMT-8:00) Pacific Time (US &amp; Canada)'),
				'-7' => T_('(GMT-7:00) Mountain Time (US &amp; Canada)'),
				'-6' => T_('(GMT-6:00) Central Time (US &amp; Canada), Mexico City'),
				'-5' => T_('(GMT-5:00) Eastern Time (US &amp; Canada), Bogota, Lima, Quito'),
				'-4' => T_('(GMT-4:00) Atlantic Time (Canada), Caracas, La Paz'),
				'-3.5' => T_('(GMT-3:30) Newfoundland'),
				'-3' => T_('(GMT-3:00) Brasilia, Buenos Aires, Georgetown'),
				'-2' => T_('(GMT-2:00) Mid-Atlantic'),
				'-1' => T_('(GMT-1:00) Azores, Cape Verde Islands'),
				'0' => T_('(GMT) Greenwich Mean Time, London, Dublin, Lisbon, Casablanca, Monrovia'),
				'1' => T_('(GMT+1:00) Amsterdam, Berlin, Rome, Copenhagen, Brussels, Madrid, Paris'),
				'2' => T_('(GMT+2:00) Athens, Istanbul, Minsk, Helsinki, Jerusalem, South Africa'),
				'3' => T_('(GMT+3:00) Baghdad, Kuwait, Riyadh, Moscow, St. Petersburg'),
				'3.5' => T_('(GMT+3:30) Tehran'),
				'4' => T_('(GMT+4:00) Abu Dhabi, Muscat, Baku, Tbilisi'),
				'4.5' => T_('(GMT+4:30) Kabul'),
				'5' => T_('(GMT+5:00) Ekaterinburg, Islamabad, Karachi, Tashkent'),
				'5.5' => T_('(GMT+5:30) Bombay, Calcutta, Madras, New Delhi'),
				'6' => T_('(GMT+6:00) Almaty, Dhaka, Colombo'),
				'7' => T_('(GMT+7:00) Bangkok, Hanoi, Jakarta'),
				'8' => T_('(GMT+8:00) Beijing, Perth, Singapore, Hong Kong, Urumqi, Taipei'),
				'9' => T_('(GMT+9:00) Tokyo, Seoul, Osaka, Sapporo, Yakutsk'),
				'9.5' => T_('(GMT+9:30) Adelaide, Darwin'),
				'10' => T_('(GMT+10:00) Brisbane, Canberra, Melbourne, Sydney, Guam,Vlasdiostok'),
				'11' => T_('(GMT+11:00) Magadan, Solomon Islands, New Caledonia'),
				'12' => T_('(GMT+12:00) Auckland, Wellington, Fiji, Kamchatka, Marshall Island'));
	}

	public static function getLocales()
	{
		return array(
				'ar_SA' => 'العربية',
				'en_US' => 'English',
				'de_DE' => 'Deutsch',
				'id_ID' => 'Bahasa Indonesia',
				'jp_JP' => '日本語',
				'jv_ID' => 'Boso Jowo',
				'kr_KR' => '한국어',
				'su_ID' => 'Basa Sunda',
				'zh_CN' => '中文');
	}
	
	public static function getMimeTypes() {
		return array(
				"323" => "text/h323",
				"acx" => "application/internet-property-stream",
				"ai" => "application/postscript",
				"aif" => "audio/x-aiff",
				"aifc" => "audio/x-aiff",
				"aiff" => "audio/x-aiff",
				"asf" => "video/x-ms-asf",
				"asr" => "video/x-ms-asf",
				"asx" => "video/x-ms-asf",
				"au" => "audio/basic",
				"avi" => "video/x-msvideo",
				"axs" => "application/olescript",
				"bas" => "text/plain",
				"bcpio" => "application/x-bcpio",
				"bin" => "application/octet-stream",
				"bmp" => "image/bmp",
				"c" => "text/plain",
				"cat" => "application/vnd.ms-pkiseccat",
				"cdf" => "application/x-cdf",
				"cer" => "application/x-x509-ca-cert",
				"class" => "application/octet-stream",
				"clp" => "application/x-msclip",
				"cmx" => "image/x-cmx",
				"cod" => "image/cis-cod",
				"cpio" => "application/x-cpio",
				"crd" => "application/x-mscardfile",
				"crl" => "application/pkix-crl",
				"crt" => "application/x-x509-ca-cert",
				"csh" => "application/x-csh",
				"css" => "text/css",
				"dcr" => "application/x-director",
				"der" => "application/x-x509-ca-cert",
				"dir" => "application/x-director",
				"dll" => "application/x-msdownload",
				"dms" => "application/octet-stream",
				"doc" => "application/msword",
				"dot" => "application/msword",
				"dvi" => "application/x-dvi",
				"dxr" => "application/x-director",
				"eps" => "application/postscript",
				"etx" => "text/x-setext",
				"evy" => "application/envoy",
				"exe" => "application/octet-stream",
				"fif" => "application/fractals",
				"flr" => "x-world/x-vrml",
				"gif" => "image/gif",
				"gtar" => "application/x-gtar",
				"gz" => "application/x-gzip",
				"h" => "text/plain",
				"hdf" => "application/x-hdf",
				"hlp" => "application/winhlp",
				"hqx" => "application/mac-binhex40",
				"hta" => "application/hta",
				"htc" => "text/x-component",
				"htm" => "text/html",
				"html" => "text/html",
				"htt" => "text/webviewhtml",
				"ico" => "image/x-icon",
				"ief" => "image/ief",
				"iii" => "application/x-iphone",
				"ins" => "application/x-internet-signup",
				"isp" => "application/x-internet-signup",
				"jfif" => "image/pipeg",
				"jpe" => "image/jpeg",
				"jpeg" => "image/jpeg",
				"jpg" => "image/jpeg",
				"js" => "application/x-javascript",
				"latex" => "application/x-latex",
				"lha" => "application/octet-stream",
				"lsf" => "video/x-la-asf",
				"lsx" => "video/x-la-asf",
				"lzh" => "application/octet-stream",
				"m13" => "application/x-msmediaview",
				"m14" => "application/x-msmediaview",
				"m3u" => "audio/x-mpegurl",
				"man" => "application/x-troff-man",
				"mdb" => "application/x-msaccess",
				"me" => "application/x-troff-me",
				"mht" => "message/rfc822",
				"mhtml" => "message/rfc822",
				"mid" => "audio/mid",
				"mny" => "application/x-msmoney",
				"mov" => "video/quicktime",
				"movie" => "video/x-sgi-movie",
				"mp2" => "video/mpeg",
				"mp3" => "audio/mpeg",
				"mpa" => "video/mpeg",
				"mpe" => "video/mpeg",
				"mpeg" => "video/mpeg",
				"mpg" => "video/mpeg",
				"mpp" => "application/vnd.ms-project",
				"mpv2" => "video/mpeg",
				"ms" => "application/x-troff-ms",
				"mvb" => "application/x-msmediaview",
				"nws" => "message/rfc822",
				"oda" => "application/oda",
				"p10" => "application/pkcs10",
				"p12" => "application/x-pkcs12",
				"p7b" => "application/x-pkcs7-certificates",
				"p7c" => "application/x-pkcs7-mime",
				"p7m" => "application/x-pkcs7-mime",
				"p7r" => "application/x-pkcs7-certreqresp",
				"p7s" => "application/x-pkcs7-signature",
				"pbm" => "image/x-portable-bitmap",
				"pdf" => "application/pdf",
				"pfx" => "application/x-pkcs12",
				"pgm" => "image/x-portable-graymap",
				"pko" => "application/ynd.ms-pkipko",
				"pma" => "application/x-perfmon",
				"pmc" => "application/x-perfmon",
				"pml" => "application/x-perfmon",
				"pmr" => "application/x-perfmon",
				"pmw" => "application/x-perfmon",
				"pnm" => "image/x-portable-anymap",
				"pot" => "application/vnd.ms-powerpoint",
				"ppm" => "image/x-portable-pixmap",
				"pps" => "application/vnd.ms-powerpoint",
				"ppt" => "application/vnd.ms-powerpoint",
				"prf" => "application/pics-rules",
				"ps" => "application/postscript",
				"pub" => "application/x-mspublisher",
				"qt" => "video/quicktime",
				"ra" => "audio/x-pn-realaudio",
				"ram" => "audio/x-pn-realaudio",
				"ras" => "image/x-cmu-raster",
				"rgb" => "image/x-rgb",
				"rmi" => "audio/mid",
				"roff" => "application/x-troff",
				"rtf" => "application/rtf",
				"rtx" => "text/richtext",
				"scd" => "application/x-msschedule",
				"sct" => "text/scriptlet",
				"setpay" => "application/set-payment-initiation",
				"setreg" => "application/set-registration-initiation",
				"sh" => "application/x-sh",
				"shar" => "application/x-shar",
				"sit" => "application/x-stuffit",
				"snd" => "audio/basic",
				"spc" => "application/x-pkcs7-certificates",
				"spl" => "application/futuresplash",
				"src" => "application/x-wais-source",
				"sst" => "application/vnd.ms-pkicertstore",
				"stl" => "application/vnd.ms-pkistl",
				"stm" => "text/html",
				"svg" => "image/svg+xml",
				"sv4cpio" => "application/x-sv4cpio",
				"sv4crc" => "application/x-sv4crc",
				"t" => "application/x-troff",
				"tar" => "application/x-tar",
				"tcl" => "application/x-tcl",
				"tex" => "application/x-tex",
				"texi" => "application/x-texinfo",
				"texinfo" => "application/x-texinfo",
				"tgz" => "application/x-compressed",
				"tif" => "image/tiff",
				"tiff" => "image/tiff",
				"tr" => "application/x-troff",
				"trm" => "application/x-msterminal",
				"tsv" => "text/tab-separated-values",
				"txt" => "text/plain",
				"uls" => "text/iuls",
				"ustar" => "application/x-ustar",
				"vcf" => "text/x-vcard",
				"vrml" => "x-world/x-vrml",
				"wav" => "audio/x-wav",
				"wcm" => "application/vnd.ms-works",
				"wdb" => "application/vnd.ms-works",
				"wks" => "application/vnd.ms-works",
				"wmf" => "application/x-msmetafile",
				"wps" => "application/vnd.ms-works",
				"wri" => "application/x-mswrite",
				"wrl" => "x-world/x-vrml",
				"wrz" => "x-world/x-vrml",
				"xaf" => "x-world/x-vrml",
				"xbm" => "image/x-xbitmap",
				"xla" => "application/vnd.ms-excel",
				"xlc" => "application/vnd.ms-excel",
				"xlm" => "application/vnd.ms-excel",
				"xls" => "application/vnd.ms-excel",
				"xlt" => "application/vnd.ms-excel",
				"xlw" => "application/vnd.ms-excel",
				"xof" => "x-world/x-vrml",
				"xpm" => "image/x-xpixmap",
				"xwd" => "image/x-xwindowdump",
				"z" => "application/x-compress",
				"zip" => "application/zip");
	}

	public static function getInstalledLocales()
	{
		$known_locales = self::getLocales();
		$locale_dirs = self::getDirectoryList(KOMA_LOCALE_PATH, '^[a-z]{2}_[A-Z]{2}$', KOMA_FILTER_REGEX);
		$locales = array();

		$locales['en_US'] = 'English';

		foreach($locale_dirs as $key => $locale_dir)
		{
			if(isset($known_locales[$locale_dir]))
			{
				$locales[$locale_dir] =  $known_locales[$locale_dir];
			}
			else
			{
				$locales[$locale_dir] = $locale_dir.' (Unidentified Language)';
			}
		}

		return $locales;
	}

	public static function getInstalledThemes()
	{
		$dir = new NS\DirectoryInfo(KOMA_ROOT_PATH.'/themes/');

		return ($dir->getDirectoriesArray());
	}

	public static function getInstalledModules()
	{
		$ic = array();
		$db = NS\DatabaseFactory::getInstance();

		$result = $db->query(sprintf("SELECT * FROM `%s`", $db->prefix('modules')));
		while($row = $db->fetchAssoc($result))
		{
			$ic[$row['mid']] = $row['name'];
		}

		return $ic;
	}

	public static function getModuleList()
	{
		return self::getDirectoryList(KOMA_ROOT_PATH.'/modules/');
	}
}
?>
